/**
 * spring board page列表. 
 */
var pageList = (function(){
    return Observable.create({
        init : function(){
            this.cardList = new CardList($('#pageList'), CardListView.urlCardTmp); 
            
            this.cardList.$itemAdder.attr('title', lan('app.im.page.create'));                               
            this.cardList.$itemAdder.click(function(){
                ujs.ui.Dialog.get(URLDialog , {
                    title : lan('app.im.page.create'),
                    relType : 'page',
                    toolbar : false,                        
                    bodyStyle : {
                        margin : 0
                    }
                });
            });            
            this.cardList.$itemAdder.tooltipster({
                theme : 'tooltipster-light',
                offsetY : -70
            });
            //删除link
            this.cardList.on('deleteItem', function(cardID){
                var _this = this;        
                bubble.confirm(lan('app.im.page.delTip'), function(){
                    page.biz.deleteLink(cardID, function(msg){
                        _this.deleteItem(cardID);    
                    }); 
                });
            });
            //编辑link
            this.cardList.on('editItem', function(cardID){ 
                var obj = page.urlStore.getItem(cardID);                
                ujs.ui.Dialog.get(URLDialog, {       
                    title : lan('app.im.page.edit'),             
                    mode : 'edit',
                    relType : 'page',
                    ueid : cardID                        
                });
            });
            this.cardList.on('cardIconClick', function(cardID){
                var obj = page.urlStore.getItem(cardID);                           
                var previewFrame = new PreviewFrame({
                        id : cardID,
                        src : obj['url'],
                        title : obj['name'],
                        relType : 'page',
                        perm : obj['perm'],
                        launchTime : obj['launchTime']
                    });                    
                sessionList.addItem(obj);
                page.contentCardLayout.addItem(cardID, previewFrame, true).showItem(cardID);                
                return false;
            });            
        }
    });
})();